#!/bin/bash
##################################################################
# File: run_sim.sh
# Co: The Neurosciences Institute
# Author: Richard G. Martin
# Purpose: Run neuronal simulations with specific configurations.
#################################################################

SETUP=$1 #read in user selected simulation setup
SIM_DIR=$2 #read in user selected projec directory

# 0) solo simulation
# 1) simulation with neuronal activity display
# 2) simulation with spike vision system
# 3) simulation with neuronal activity display and spike vision system
sim_setup=$SETUP

#set this Parameter to simulation directory, i.e. /home/martin/Projects/nnrobot/dummy_sim
sim_dir=$SIM_DIR

sim_host=10.11.2.13
#sim_host=martin@stark

#set this Parameter to the simulation binary name
sim_bin=main
#set this Parameter to the dummy simulation binary name
dummy_bin=dummy_sim

#set this Parameter to the display absolute directory, i.e. /home/martin/Projects/display
disp_dir=/home/martin/Projects/nsi/display/display
disp_host=10.11.2.13
#disp_dir=/home/drathm/Displays/current/display
#disp_host=drathm@10.11.2.42
#disp_dir=/Users/drathm/Projects/nsi/display/display
#disp_host=drathm@10.11.2.23

#set this Parameter to the display absolute directory, i.e. /home/martin/Projects/display
#NOTE: spike display
#spike_dir=/home/kozarev/Projects/nsi/spike/spike/build/spike/spike
#spike_host=kozarev@10.11.2.24
spike_dir=/home/drathm/Projects/nsi/spike_new/build/spike/spike
spike_host=drathm@10.11.2.42

# current numbers are to take into account the anti-reflective screen
# setup no longer needs the outside barrier to shade reflections
PIXEL_THR=90 #60
PIXEL_SET=225 #175
spike_cam_url=http://10.11.2.242/axis-cgi/mjpg/video.cgi?resolution=160x120.mjpeg

#spike_disp_dir=/home/drathm/Projects/nsi/spike_display/spike/spike
#spike_dir=/home/drathm/Projects/nsi/spike_filter/spike/spike


TIME=1200000

NUM_PROCS=8

case $sim_setup in
  0) time /usr/local/openmpi/bin/mpirun --tag-output -d -np 7 -H $sim_host $sim_dir/$sim_bin : -np 1 -H $sim_host $sim_dir/$dummy_bin;;
  1) time /usr/local/openmpi/bin/mpirun --tag-output -d -np $NUM_PROCS -H $sim_host $sim_dir/$sim_bin : -np 1 -H $sim_host $sim_dir/$dummy_bin : -np 1 -H $disp_host -x DISPLAY=:0.0 $disp_dir;;
  2) time /usr/local/openmpi/bin/mpirun --tag-output -d -np $NUM_PROCS -H $sim_host $sim_dir/$sim_bin : -np 1 -H $spike_host -x LD_LIBRARY_PATH=/usr/local/cuda/lib64 $spike_dir --pixel_thr=$PIXEL_THR --pixel_set=$PIXEL_SET --mpi --stream -d 1 -o 0 -t $TIME $spike_cam_url;;
  3) time /usr/local/openmpi/bin/mpirun --tag-output -d -np $NUM_PROCS -H $sim_host $sim_dir/$sim_bin : -np 1 -H $spike_host -x LD_LIBRARY_PATH=/usr/local/cuda/lib64 $spike_dir --pixel_thr=$PIXEL_THR --pixel_set=$PIXEL_SET --display --mpi --stream -d 1 -o 0 -t $TIME $spike_cam_url : -np 1 -H $disp_host -x DISPLAY=:0.0 $disp_dir;;
esac
